package chapter17;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * @author lzy
 * @version v1.0
 * Create DateTime: 2019/2/24 15:35
 */
public class ScheduleThreadPoolTest {
    public static void main(String[] args) {
        ScheduledExecutorService executor = Executors.newScheduledThreadPool(10);
        executor.scheduleWithFixedDelay(() -> {
            try {
                TimeUnit.SECONDS.sleep(2);
                System.out.println("long time work");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }, 10, 1000, TimeUnit.MILLISECONDS);

        executor.scheduleWithFixedDelay(() -> {
            System.out.println("fixed rate");
        }, 100, 1000, TimeUnit.MILLISECONDS);
    }
}
